home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
001-100
/
001-025
/
014
/
dex
/
dex.y
< prev
next >
Wrap
Text File
|
1995-03-17
|
4KB
|
172 lines
%{
/************************************************************************
* *
* Copyright (c) 1982, Fred Fish *
* All Rights Reserved *
* *
* This software and/or documentation is released for public *
* distribution for personal, non-commercial use only. *
* Limited rights to use, modify, and redistribute are hereby *
* granted for non-commercial purposes, provided that all *
* copyright notices remain intact and all changes are clearly *
* documented. The author makes no warranty of any kind with *
* respect to this product and explicitly disclaims any implied *
* warranties of merchantability or fitness for any particular *
* purpose. *
* *
************************************************************************
*/
%}
/*
* FILE
*
* dex.y YACC grammar for documentation extraction utility
*
* KEY WORDS
*
* YACC specifications
* dex grammar
*
* SYNOPSIS
*
* yacc dex.y
* mv y.tab.c dex.c
*
* DESCRIPTION
*
* This file contains the yacc grammar specification for the
* documentation extraction utility "dex". Along with the
* file "dex.l", which is the lex specification, this file
* implements much of the control structure for extracting
* documentation from program source files and compiling
* it into a form suitable for input to the NROFF text formatter.
*
* BUGS
*
* Since the author is still learning parsing techniques,
* grammar definition, etc, the grammar probably has
* some rough spots.
*
* Error reporting is minimal and currently processing
* stops with the first error found in a given file.
*
* AUTHOR
*
* Fred Fish
*
*/
%{
#include <stdio.h>
#define TRUE 1
#define FALSE 0
char savedtext[256]; /* Text for current line */
extern char *infile; /* Input file name if not stdin */
extern int linenum; /* Current input file line number */
extern FILE *infp; /* Input stream */
extern int debug; /* Debug variable */
%}
%token BSTART TEXT JUNK HSTART FSTART UFSTART NEWLINE
%%
file : line
{if(debug){printf("yyparse: file\n");}}
| file line
{if(debug){printf("yyparse: file\n");}}
| /* empty */
{if(debug){printf("yyparse: file\n");}}
;
line : junk
{
if(debug){printf("yyparse: line\n");}
reset_section();
}
| id_line
{if(debug){printf("yyparse: line\n");}}
| blank_line
{if(debug){printf("yyparse: line\n");}}
| filled_line
{if(debug){printf("yyparse: line\n");}}
| unfilled_line
{if(debug){printf("yyparse: line\n");}}
;
junk : JUNK
{if(debug){printf("yyparse: junk\n");}}
| newline
{if(debug){printf("yyparse: junk\n");}}
| junk newline
{if(debug){printf("yyparse: junk\n");}}
;
id_line : HSTART text newline
{
{if(debug){printf("yyparse: id_line\n");}}
set_section(savedtext);
}
;
blank_line : BSTART newline
{
{if(debug){printf("yyparse: blank_line\n");}}
emit_bline();
}
;
filled_line : FSTART text newline
{
{if(debug){printf("yyparse: filled_line\n");}}
emit_filled(savedtext);
}
;
unfilled_line : UFSTART text newline
{
{if(debug){printf("yyparse: unfilled_line\n");}}
emit_unfilled(savedtext);
}
;
newline : NEWLINE
{
{if(debug){printf("yyparse: newline\n");}}
linenum++;
}
;
text : TEXT
{
{if(debug){printf("yyparse: text\n");}}
strcpy(savedtext,yytext);
}
;
%%
#include "dex.lo" /* LEX output; renamed from lex.yy.c */
yywrap () /* Thought this was in library */
{
return(1);
}
yyerror(sp)
char *sp;
{
fprintf(stderr,"%s: ",infile); /* What file */
fprintf(stderr,"line %d: ",linenum); /* Where in file */
fprintf(stderr,"%s: ",sp); /* What was wrong */
fprintf(stderr,"%s\n",yytext); /* What it choked on */
}